/*
 * Copyright (c) 2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.wso2.carbon.registry.lifecycle.accenture.sample.utils;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CustomEmailMessageUtil {
    private static final Log log = LogFactory.getLog(CustomEmailMessageUtil.class);

    //Defined states in the LC
    private static final String NEWREQUEST = "NewRequest";
    private static final String DESIGNSTARTED = "DesignStarted";
    private static final String DESIGNDONE = "DesignDone";
    private static final String DELIVERYINPROGRESS = "DeliveryInprogress";
    private static final String DELIVERYDONE = "DeliveryDone";
    private static final String UATDONE = "UATDone";
    private static final String DEPLOY = "Deploy";
    private static final String DEPLOYED = "Deployed";
    private static final String DISMISS = "Dismiss";

    //Defined state transition actions in the LC
    private static final String PROMOTE = "Promote";
    private static final String DEMOTE = "Demote";
    private static final String NOTAPPROVED = "NotApproved";




    public static String generateMessageFromStateAndAction(String state, String action, String serviceName, String servicePath) throws Exception {
        if (state.equals(NEWREQUEST) && action.equals(PROMOTE)) {
            return getNewRequestPromoteMessage(serviceName, servicePath);
        } else if (state.equals(DESIGNSTARTED) && action.equals(PROMOTE)) {
            return getDesignStartedPromoteMessage(serviceName, servicePath);
        } else if (state.equals(DESIGNDONE) && action.equals(PROMOTE)) {
            return getDesignDonePromoteMessage(serviceName, servicePath);
        } else if (state.equals(DESIGNDONE) && action.equals(NOTAPPROVED)) {
            return getDesignDoneNotApprovedMessage(serviceName, servicePath);
        } else if (state.equals(DELIVERYINPROGRESS) && action.equals(PROMOTE)) {
            return getDeliveryInprogressPromoteMessage(serviceName, servicePath);
        } else if (state.equals(DELIVERYDONE) && action.equals(PROMOTE)) {
            return getDeliveryDonePromoteMessage(serviceName, servicePath);
        } else if (state.equals(UATDONE) && action.equals(PROMOTE)) {
            return getUATDonePromoteMessage(serviceName, servicePath);
        } else if (state.equals(DEPLOY) && action.equals(PROMOTE)) {
            return getDeployPromoteMessage(serviceName, servicePath);
        } else if (state.equals(DEPLOYED) && action.equals(PROMOTE)) {
            return getDeployedPromoteMessage(serviceName, servicePath);
        } else if (state.equals(DISMISS) && action.equals(PROMOTE)) {
            return getDismissPromoteMessage(serviceName, servicePath);
        } else {
            String errorMsg = "Relavant message could not be generated for state:" + state + ", action:"
                      + action + ", service:" + serviceName + ", service path:" + servicePath + " ";
            log.error(errorMsg);
            throw new Exception(errorMsg);
        }
    }

    public static String getNewRequestPromoteMessage (String serviceName, String servicePath) {
        String msg = "New Service Request for " + serviceName + " was created and available at a path:" +
                     servicePath + " ";
        return msg;
    }

    private static String getDesignStartedPromoteMessage (String serviceName, String servicePath) {
        String msg = "Design of Service " + serviceName + " was finished and ready for approvement at " +
                     "the path:" + servicePath + " ";
        return msg;
    }

    private static String getDesignDonePromoteMessage (String serviceName, String servicePath) {
        String msg = "Design of Service " + serviceName + "  was approved and ready for Development " +
                     "at the path:" + servicePath + " ";
        return msg;
    }

    private static String getDesignDoneNotApprovedMessage(String serviceName, String servicePath) {
        String msg = "Design of Service " + serviceName + " was not approved and demoted. Please check " +
                     "for review comments at the path:" + servicePath + " ";
        return msg;
    }

    private static String getDeliveryInprogressPromoteMessage (String serviceName, String servicePath) {
        String msg = "Development for Service " + serviceName + " was finished and ready for test at " +
                     "the path:" + servicePath + " ";
        return msg;
    }

    private static String getDeliveryDonePromoteMessage (String serviceName, String servicePath) {
        String msg = "Service " + serviceName + " was correctly tested at the path:" + servicePath + " ";
        return msg;
    }

    private static String getUATDonePromoteMessage (String serviceName, String servicePath) {
        String msg = "Service " + serviceName + " ready for Deploy at the path:" + servicePath + " ";
        return msg;
    }

    private static String getDeployPromoteMessage (String serviceName, String servicePath) {
        String msg = "Service " + serviceName + " was Deployed and available at the path:" + servicePath + " ";
        return msg;
    }

    private static String getDeployedPromoteMessage (String serviceName, String servicePath) {
        String msg = "Service " + serviceName + " was Dismissed. Latest available path is:" + servicePath + " ";
        return msg;
    }

    private static String getDismissPromoteMessage (String serviceName, String servicePath) {
        String msg = "Service " + serviceName + " was Deprecated. Latest available path is:" + servicePath + " ";
        return msg;
    }
}
